/* liquidity.ado (STATA)
	Estimate price impact */

clear all

******************************************************************************
* Specify working directory
******************************************************************************

* For example
* cd "/Users/.../XYZ/"

global rawdata "Data/Raw_Data"
global tempdata "Data/RevisionRFS/temp_data"
global masterdata "Data/Master_Data"
global revisiondata "Data/RevisionRFS"
global revisionfigures = "Results/RevisionRFS/Figures"
global revisionoutput = "Results/RevisionRFS/Output"


use "${revisionoutput}/panel_reg_ts_hy_qs_pooled_fs_non_std.dta",  clear

drop if type_new2 == 5

append using "${revisionoutput}/panel_reg_ts_hy_qs_pooled_fs_non_std_etf.dta"

rename _b_yield _b_yieldhat, replace
gen assetclass = 2

save "${revisionoutput}/panel_reg_ts_hy_qs_pooled_fs_non_std_v2.dta", replace

use "${revisionoutput}/panel_reg_ts_ig_qs_pooled_fs_non_std.dta",  clear

drop if type_new2 == 5

append using "${revisionoutput}/panel_reg_ts_ig_qs_pooled_fs_non_std_etf.dta"

gen assetclass = 1

save "${revisionoutput}/panel_reg_ts_ig_qs_pooled_fs_non_std_v2.dta", replace

use "${revisionoutput}/panel_reg_ts_hy_qs_pooled_fs_non_std_v2.dta", clear 

append using "${revisionoutput}/panel_reg_ts_ig_qs_pooled_fs_non_std_v2.dta"

save "${revisionoutput}/panel_reg_ts_qs_pooled_fs_non_std_v2.dta"

/* Price Elasticity Analysis */

#delimit ;

/* Load data */
u date fundid type_new2 bondid assetclass price_eom yield ytm timetomat lambda _b_ss_price_iv
	LNtimetomat rating_num holding spread LNbv coupon_dec aum_assetclass aum_tot _b_ss_yield_iv
	if holding>0 & type_new2 > 0
	using "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;

merge m:1 type_new2 assetclass date using "${revisionoutput}/panel_reg_ts_qs_pooled_fs_non_std_v2.dta";
keep if _merge == 3;
drop _merge;

gen weight_assetclass = aum_assetclass/aum_tot;
gen weight_conditional = holding/aum_assetclass;
gen weight = holding/aum_tot;

gen _b_price = -_b_yieldhat/timetomat;
gen elasticity = 1 - (1 - weight_assetclass)*weight_conditional*lambda*_b_price - (1 - weight_conditional)*_b_price;

gegen elasticity_fund_ac = sum(elasticity*holding/aum_assetclass), by(fundid assetclass date);

bysort date fundid assetclass: gen aum_assetclass_sum = aum_assetclass if _n == 1;
replace aum_assetclass_sum = 0 if aum_assetclass_sum ==.;
gegen aum_assetclass_type = sum(aum_assetclass_sum), by(type_new2 assetclass date);
bysort date fundid assetclass: gen elasticity_fund_ac_sum = elasticity_fund_ac if _n == 1;
replace elasticity_fund_ac_sum = 0 if elasticity_fund_ac_sum ==.;
gegen elasticity_type_ac = sum(elasticity_fund_ac_sum*aum_assetclass/aum_assetclass_type), by(type_new2 assetclass date);

gegen elasticity_fund = sum(elasticity*holding/aum_tot), by(fundid date);

bysort date fundid: gen aum_tot_sum = aum_tot if _n == 1;
replace aum_tot_sum = 0 if aum_tot_sum ==.;
gegen aum_tot_type = sum(aum_assetclass_sum), by(type_new2 date);
bysort date fundid: gen elasticity_fund_sum = elasticity_fund if _n == 1;
replace elasticity_fund_sum = 0 if elasticity_fund_sum ==.;
gegen elasticity_type = sum(elasticity_fund_sum*aum_tot/aum_tot_type), by(type_new2 date);

gegen holdings_obs = sum(holding) if type_new2 != 0, by(bondid date);
gegen holdings_bond_tot = sum(holding), by(date bondid);
gegen elasticity_bond_obs = sum(elasticity*holding/holdings_obs), by(bondid date);



preserve

gcollapse elasticity_type, by( date type_new2)

tabstat elasticity_type, s(mean median p10 p90 sd N) by(type_new2)

tabstat elasticity_type if date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min max sd N) by(type_new2)

tabstat elasticity_type if date > `=tq(2009q4)', s(mean median min max sd N) by(type_new2)

restore 


preserve

gcollapse elasticity_type_ac, by(type_new2 assetclass date)

winsor2 elasticity_type_ac, cuts(5 95) by(type_new2)
// get rid of periods with not enough observations
drop if type_new2 == 5 & assetclass == 2 & date <= `=tq(2012q4)'
tabstat elasticity_type_ac_w if assetclass == 1 , s(mean median min max sd N) by(type_new2)
tabstat elasticity_type_ac_w if assetclass == 1 & date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min max sd N) by(type_new2)
tabstat elasticity_type_ac_w if assetclass == 1 & date >= `=tq(2009q4)', s(mean median min max sd N) by(type_new2)

tabstat elasticity_type_ac_w if assetclass == 2, s(mean median min max sd N) by(type_new2)
tabstat elasticity_type_ac_w if assetclass == 2 & date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min max sd N) by(type_new2)
tabstat elasticity_type_ac_w if assetclass == 2 & date >= `=tq(2009q4)', s(mean median min max sd N) by(type_new2)

restore


/* Bond Level and Market-wide Elasticities */

/* Full Sample */
preserve

gcollapse elasticity_bond_obs assetclass LNbv, by(bondid date)

// tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) 
tabstat elasticity_bond_obs if date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) 
tabstat elasticity_bond_obs if date >= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N)


gen amt_out = exp(LNbv)
gcollapse elasticity_bond_obs [aw=amt_out], by(date)

tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) 
tabstat elasticity_bond_obs if date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) 
tabstat elasticity_bond_obs if date >= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N)

restore 


/* By Credit Rating Group */

preserve

gcollapse elasticity_bond_obs assetclass LNbv, by(bondid date)

// tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs if date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs if date >= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) by(assetclass)


gen amt_out = exp(LNbv)
gcollapse elasticity_bond_obs [aw=amt_out], by(assetclass date)

tabstat elasticity_bond_obs, s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs if date >= `=tq(2006q1)' & date <= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) by(assetclass)
tabstat elasticity_bond_obs if date >= `=tq(2009q4)', s(mean median min p10 p25 p90 max sd N) by(assetclass)

restore 




#delimit ;

use "${revisiondata}/liquidity/liquidity_184", clear;

forval q = `=tq(2006q2)'(1)`=tq(2020q3)' {;

append using "${revisiondata}/liquidity/liquidity_`q'";

};

save "${revisiondata}/liquidity/liquidity", replace;


/* Price Impact Analysis */
	
#delimit ;

/* Load data */
u date fundid type_new2 bondid assetclass price_eom yield ytm timetomat
	LNtimetomat rating_num holding spread LNbv coupon_dec 
	if holding>0
	using "${revisiondata}/counterfactuals/counterfactuals_data.dta", clear;
	
drop if type_new2 == 0;
gegen holding_tot =sum(holding), by(bondid date);
gegen holding_mf =sum((type_new2==3)*holding), by(bondid date);
gegen holding_life =sum((type_new2==1)*holding), by(bondid date);
gegen holding_pc =sum((type_new2==2)*holding), by(bondid date);
gegen holding_etf =sum((type_new2==5)*holding), by(bondid date);
gen frac_mf = holding_mf/holding_tot;
gen frac_life = holding_life/holding_tot;
gen frac_pc = holding_pc/holding_tot;
gen frac_etf = holding_etf/holding_tot;

collapse assetclass LNtimetomat rating_num spread LNbv coupon_dec frac_mf frac_life frac_pc frac_etf price_eom yield ytm timetomat, by(date bondid);

merge 1:1 date bondid using "${revisiondata}/liquidity/liquidity";
drop _merge;

winsor2 liquidA, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidA1, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidA2, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidmf, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidmf1, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidmf2, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidetf, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidetf1, replace cuts(1 99) trim by(date assetclass);
winsor2 liquidetf2, replace cuts(1 99) trim by(date assetclass);

gen price_hatA = price_eom*(1-liquidA);
gen yield_hatA = -ln(price_hatA/100)/timetomat;
gen liquid_pc_yieldA = (yield_hatA - yield)/ytm;
gen liquid_yieldA = 100*(yield_hatA - yield);

gen price_hatA1 = price_eom*(1-liquidA1);
gen yield_hatA1 = -ln(price_hatA1/100)/timetomat;
gen liquid_pc_yieldA1 = (yield_hatA1 - yield)/ytm;
gen liquid_yieldA1 = 100*(yield_hatA1 - yield);

gen price_hatA2 = price_eom*(1-liquidA2);
gen yield_hatA2 = -ln(price_hatA2/100)/timetomat;
gen liquid_pc_yieldA2 = (yield_hatA2 - yield)/ytm;
gen liquid_yieldA2 = 100*(yield_hatA2 - yield);

gen price_hatmf = price_eom*(1-liquidmf);
gen yield_hatmf = -ln(price_hatmf/100)/timetomat;
gen liquid_pc_yieldmf = (yield_hatmf - yield)/ytm;
gen liquid_yieldmf = 100*(yield_hatmf - yield);

gen price_hatmf1 = price_eom*(1-liquidmf1);
gen yield_hatmf1 = -ln(price_hatmf1/100)/timetomat;
gen liquid_pc_yieldmf1 = (yield_hatmf1 - yield)/ytm;
gen liquid_yieldmf1 = 100*(yield_hatmf1 - yield);

gen price_hatmf2 = price_eom*(1-liquidmf2);
gen yield_hatmf2 = -ln(price_hatmf2/100)/timetomat;
gen liquid_pc_yieldmf2 = (yield_hatmf2 - yield)/ytm;
gen liquid_yieldmf2 = 100*(yield_hatmf2 - yield);

gen price_hatetf = price_eom*(1-liquidetf);
gen yield_hatetf = -ln(price_hatetf/100)/timetomat;
gen liquid_pc_yieldetf = (yield_hatetf - yield)/ytm;
gen liquid_yieldetf = 100*(yield_hatetf - yield);

gen price_hatetf1 = price_eom*(1-liquidetf1);
gen yield_hatetf1 = -ln(price_hatetf1/100)/timetomat;
gen liquid_pc_yieldetf1 = (yield_hatetf1 - yield)/ytm;
gen liquid_yieldetf1 = 100*(yield_hatetf1 - yield);

gen price_hatetf2 = price_eom*(1-liquidetf2);
gen yield_hatetf2 = -ln(price_hatetf2/100)/timetomat;
gen liquid_pc_yieldetf2 = (yield_hatetf2 - yield)/ytm;
gen liquid_yieldetf2 = 100*(yield_hatetf2 - yield);



/* -----------------------------------------------------------------------------
--------------- Cross-sectional distribution of price impact -------------------
----------------------------------------------------------------------------- */

su liquidA if date == `=tq(2008q4)', d
su liquidA1 if date == `=tq(2008q4)', d
su liquidA2 if date == `=tq(2008q4)', d
su liquidA3 if date == `=tq(2008q4)', d

gen liquidA_100 = -100*liquidA
label var liquidA_100 "percent price change"


/* Investment Grade Bonds */

su liquidA_100 if date == `=tq(2008q4)' & assetclass == 1, d

histogram liquidA_100 if date == `=tq(2008q4)' & assetclass == 1, freq ylabel (0(50)400) xaxis(1 2) subtitle("IG Bonds: Aggregate Price Impact ") xlabel(-8.28 "mean" -0.68 " +2 s.d." -4.48 "+1 s.d." -12.08 " -1 s.d." -15.88 "-2 s.d." -19.68 "-3 s.d." -23.48 "-4 s.d." -27.28 "-5 s.d.",axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histA.pdf", as(pdf) replace

gen liquidA1_100 = -100*liquidA1
label var liquidA1_100 "percent price change"

su liquidA1_100 if date == `=tq(2008q4)' & assetclass == 1, d

histogram liquidA1_100 if date == `=tq(2008q4)' & assetclass == 1, freq ylabel (0(50)400) xaxis(1 2) subtitle("IG Bonds: Aggregate Price Impact - No Within Type and Rating Group Elasticity Variation") xlabel(-8.24 "mean" -0.91 " +2 s.d." -4.57 " +1 s.d." -11.91 " -1 s.d." -15.57 "-2 s.d." -19.24 "-3 s.d." -22.90 "-4 s.d." -26.56 "-5 s.d." ,axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histA1.pdf", as(pdf) replace

gen liquidA2_100 = -100*liquidA2
label var liquidA2_100 "percent price change"

su liquidA2_100 if date == `=tq(2008q4)' & assetclass == 1, d

histogram liquidA2_100 if date == `=tq(2008q4)' & assetclass == 1, freq ylabel (0(50)200) xaxis(1 2) subtitle("IG Bonds: Aggregate Price Impact - No Within Rating Group Elasticity Variation") xlabel(-6.769 "mean" -6.765 " +2 s.d." -6.767 " +1 s.d." -6.771 " -1 s.d." -6.773 "-2 s.d." -6.775 "-3 s.d." -6.777 "-4 s.d." -6.779 "-5 s.d." ,axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histA2.pdf", as(pdf) replace


/* High Yield Bonds */

su liquidA_100 if date == `=tq(2008q4)' & assetclass == 2, d

histogram liquidA_100 if date == `=tq(2008q4)' & assetclass == 2, freq ylabel (0(50)100) xaxis(1 2) subtitle("HY Bonds: Aggregate Price Impact ") xlabel(-13.57 "mean" -8.67 " +2 s.d." -11.12 " +1 s.d." -16.02 " -1 s.d." -18.47 "-2 s.d." -20.92 "-3 s.d." -23.37 "-4 s.d." -25.82 "-5 s.d.",axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histAHY.pdf", as(pdf) replace

su liquidA1_100 if date == `=tq(2008q4)' & assetclass == 2, d

histogram liquidA1_100 if date == `=tq(2008q4)' & assetclass == 2, freq ylabel (0(50)100) xaxis(1 2) subtitle("HY Bonds: Aggregate Price Impact - No Within Type and Rating Group Elasticity Variation") xlabel(-13.50 "mean" -8.46 " +2 s.d." -10.98  " +1 s.d." -16.02" -1 s.d." -18.54 "-2 s.d." -21.06 "+3 s.d." -23.58 "+4 s.d." -26.10 "+5 s.d." ,axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histA1HY.pdf", as(pdf) replace


su liquidA2_100 if date == `=tq(2008q4)' & assetclass == 2, d

histogram liquidA2_100 if date == `=tq(2008q4)' & assetclass == 2, freq ylabel (0(50)150) xaxis(1 2) subtitle("HY Bonds: Aggregate Price Impact - No Within Rating Group Elasticity Variation") xlabel(-13.33 "mean" -13.256 " +2 s.d." -13.293  " +1 s.d." -13.367 " -1 s.d." -13.404 "-2 s.d." -13.219 "+3 s.d." -13.182 "+4 s.d." -13.145 "+5 s.d." ,axis(2) grid) xtitle("", axis(2)) xlabel(,axis(1) nogrid)
graph export "${revisionfigures}/liquidity_histA2HY.pdf", as(pdf) replace




format date %tq

gen year_quarter = string(date, "%tqCCYY:q")



preserve

collapse (median) liquidA_100 (p5) liquidA_10025=liquidA_100 (p95) liquidA_10075=liquidA_100, by(date assetclass) fast


twoway ///
(connected liquidA_100 date if assetclass == 1, lwidth(medium) lpattern("l") lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquidA_10025 date if assetclass == 1, lwidth(thin) lpattern(longdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquidA_10075 date if assetclass == 1, lwidth(thin) lpattern(shortdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
, ///
title("Investment Grade Bonds", size(medsmall) color(black)) ytitle("Percent Point Changes in Prices") ytitle(, size(small)) ///
ylabel(-5(5)-30, format(%5.1f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(7) region(lwidth(none) color(none)) label(1 "median") label(2 "p5") label(3 "p95") order(1 2 3) size(small)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/liquidityA_TS.pdf", as(pdf) replace


restore


preserve

collapse (median) liquidA_100 (p5) liquidA_10025=liquidA_100 (p95) liquidA_10075=liquidA_100, by(date assetclass) fast


twoway ///
(connected liquidA_100 date if assetclass == 2, lwidth(medium) lpattern("l") lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquidA_10025 date if assetclass == 2, lwidth(thin) lpattern(longdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquidA_10075 date if assetclass == 2, lwidth(thin) lpattern(shortdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
, ///
title("High Yield Bonds", size(medsmall) color(black)) ytitle("Percent Point Changes in Prices") ytitle(, size(small)) ///
ylabel(-5(5)-30, format(%5.1f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(7) region(lwidth(none) color(none)) label(1 "median") label(2 "p5") label(3 "p95") order(1 2 3) size(small)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/liquidityAHY_TS.pdf", as(pdf) replace


restore




preserve

merge m:1 date bondid using "${revisiondata}/counterfactuals/large_mf_bond_dummies.dta"

keep if frac_mf > 0.4

replace liquid_yieldmf = liquid_yieldmf*25

collapse (median) liquid_yieldmf (p25) liquid_yieldmf25=liquid_yieldmf (p75) liquid_yieldmf75=liquid_yieldmf, by(date assetclass large_mf_bond) fast


twoway ///
(connected liquid_yieldmf date if assetclass == 1 & large_mf_bond == 1, lwidth(medium) lpattern("l") lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldmf25 date if assetclass == 1 & large_mf_bond == 1, lwidth(thin) lpattern(longdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldmf75 date if assetclass == 1 & large_mf_bond == 1, lwidth(thin) lpattern(shortdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldmf date if assetclass == 2 & large_mf_bond == 1, lwidth(medium) lpattern("l") lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquid_yieldmf25 date if assetclass == 2 & large_mf_bond == 1, lwidth(thin) lpattern(longdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquid_yieldmf75 date if assetclass == 2 & large_mf_bond == 1, lwidth(thin) lpattern(shortdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
, ///
title("25% Shock to Mutual Funds' Latent Demand", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.1f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(11) region(lwidth(none) color(none)) label(1 "IG bonds - median") label(2 "IG bonds - p25") label(3 "IG bonds - p75") label(4 "HY bonds - median") label(5 "HY bonds - p25") label(6 "HY bonds - p75") order(1 2 3 4 5 6) size(small)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/MF_pi.pdf", as(pdf) replace


restore



preserve

merge m:1 date bondid using "${revisiondata}/counterfactuals/bond_holding_dummies.dta"

keep if frac_etf > 0.15

replace liquid_yieldetf = liquid_yieldetf*25

gen number_bonds = 1

collapse (median) liquid_yieldetf (p25) liquid_yieldetf25=liquid_yieldetf (p75) liquid_yieldetf75=liquid_yieldetf (sum) number_bonds, by(date assetclass ) fast

su number_bonds, d

twoway ///
(connected liquid_yieldetf date if assetclass == 1  & number_bonds > 10, lwidth(medium) lpattern("l") lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldetf25 date if assetclass == 1  & number_bonds > 10, lwidth(thin) lpattern(longdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldetf75 date if assetclass == 1  & number_bonds > 10, lwidth(thin) lpattern(shortdash) lcolor(maroon) msymbol(i) mcolor(maroon) msize(small)) ///
(connected liquid_yieldetf date if assetclass == 2 & number_bonds > 10, lwidth(medium) lpattern("l") lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquid_yieldetf25 date if assetclass == 2  & number_bonds > 10, lwidth(thin) lpattern(longdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
(connected liquid_yieldetf75 date if assetclass == 2  & number_bonds > 10, lwidth(thin) lpattern(shortdash) lcolor(edkblue) msymbol(i) mcolor(edkblue) msize(small)) ///
, ///
title("25% Shock to ETFs' Latent Demand", size(medsmall) color(black)) ytitle("Changes in Credit Spreads (bps)") ytitle(, size(small)) ///
ylabel(, format(%5.1f) labsize(small) angle(horizontal) grid glcolor(gs15)) xtitle("Year") xtitle(, size(small)) ///
xlabel(184(8)242, valuelabel labsize(small))  ///
legend(ring(0) position(11) region(lwidth(none) color(none)) label(1 "IG bonds - median") label(2 "IG bonds - p25") label(3 "IG bonds - p75") label(4 "HY bonds - median") label(5 "HY bonds - p25") label(6 "HY bonds - p75") order(1 2 3 4 5 6) size(small)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white) 

graph export "${revisionfigures}/ETF_pi.pdf", as(pdf) replace

restore



